﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace QLNHK.BLL
{
	public partial class NhanKhau_TomTatBanThan : Ent_Base, ICloneable
	{
        #region Variables
        
		private int _iD;
		private string _tuThangNamDenThangNam = string.Empty;
		private string _choO = string.Empty;
		private string _ngheNghiepNoiLamViec = string.Empty;
		private long _nhanKhauID;
        
        #endregion
    
        //---------------------------------------------------------------------------------------------
        
		#region Properties.
		
		public int ID 
        { 
            get { return  _iD; } 
            set
            {
                _iD = value;
                OnPropertyChanged("ID");
            }
        }
		public string TuThangNamDenThangNam 
        { 
            get { return  _tuThangNamDenThangNam; } 
            set
            {
                _tuThangNamDenThangNam = value;
                OnPropertyChanged("TuThangNamDenThangNam");
            }
        }
		public string ChoO 
        { 
            get { return  _choO; } 
            set
            {
                _choO = value;
                OnPropertyChanged("ChoO");
            }
        }
		public string NgheNghiepNoiLamViec 
        { 
            get { return  _ngheNghiepNoiLamViec; } 
            set
            {
                _ngheNghiepNoiLamViec = value;
                OnPropertyChanged("NgheNghiepNoiLamViec");
            }
        }
		public long NhanKhauID 
        { 
            get { return  _nhanKhauID; } 
            set
            {
                _nhanKhauID = value;
                OnPropertyChanged("NhanKhauID");
            }
        }
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Methods
		protected static List<NhanKhau_TomTatBanThan> ConvertToCollection(IDataReader reader)
		{
			List<NhanKhau_TomTatBanThan> collection = new List<NhanKhau_TomTatBanThan>();
			while (reader.Read())
			{
				NhanKhau_TomTatBanThan entity = new NhanKhau_TomTatBanThan();
				if (!reader.IsDBNull(reader.GetOrdinal("ID"))) entity.ID = reader.GetInt32(reader.GetOrdinal("ID"));
				if (!reader.IsDBNull(reader.GetOrdinal("TuThangNamDenThangNam"))) entity.TuThangNamDenThangNam = reader.GetString(reader.GetOrdinal("TuThangNamDenThangNam"));
				if (!reader.IsDBNull(reader.GetOrdinal("ChoO"))) entity.ChoO = reader.GetString(reader.GetOrdinal("ChoO"));
				if (!reader.IsDBNull(reader.GetOrdinal("NgheNghiepNoiLamViec"))) entity.NgheNghiepNoiLamViec = reader.GetString(reader.GetOrdinal("NgheNghiepNoiLamViec"));
				if (!reader.IsDBNull(reader.GetOrdinal("NhanKhauID"))) entity.NhanKhauID = reader.GetInt64(reader.GetOrdinal("NhanKhauID"));
				collection.Add(entity);
			}
			reader.Close();
			return collection;
		}
		
		public static bool Find(List<NhanKhau_TomTatBanThan> collection, int iD)
        {
            foreach (NhanKhau_TomTatBanThan item in collection)
            {
                if (item.ID == iD)
                {
                    return true;
                }
            }

            return false;
        }
		
		public static void UpdateDataSet(DataSet ds)
        {
            string insert = "Insert INTO t_NhanKhau_TomTatBanThan VALUES(@TuThangNamDenThangNam, @ChoO, @NgheNghiepNoiLamViec, @NhanKhauID)";
            string update = "UPDATE t_NhanKhau_TomTatBanThan SET TuThangNamDenThangNam = @TuThangNamDenThangNam, ChoO = @ChoO, NgheNghiepNoiLamViec = @NgheNghiepNoiLamViec, NhanKhauID = @NhanKhauID WHERE ID = @ID";
            string delete = "DELETE FROM t_NhanKhau_TomTatBanThan WHERE ID = @ID";

			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();

            System.Data.Common.DbCommand InsertCommand = db.GetSqlStringCommand(insert);
			db.AddInParameter(InsertCommand, "@ID", SqlDbType.Int, "ID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TuThangNamDenThangNam", SqlDbType.NVarChar, "TuThangNamDenThangNam", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ChoO", SqlDbType.NVarChar, "ChoO", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgheNghiepNoiLamViec", SqlDbType.NVarChar, "NgheNghiepNoiLamViec", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NhanKhauID", SqlDbType.BigInt, "NhanKhauID", DataRowVersion.Current);

            System.Data.Common.DbCommand UpdateCommand = db.GetSqlStringCommand(update);
			db.AddInParameter(UpdateCommand, "@ID", SqlDbType.Int, "ID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TuThangNamDenThangNam", SqlDbType.NVarChar, "TuThangNamDenThangNam", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ChoO", SqlDbType.NVarChar, "ChoO", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgheNghiepNoiLamViec", SqlDbType.NVarChar, "NgheNghiepNoiLamViec", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NhanKhauID", SqlDbType.BigInt, "NhanKhauID", DataRowVersion.Current);
			
            System.Data.Common.DbCommand DeleteCommand = db.GetSqlStringCommand(delete);
			db.AddInParameter(DeleteCommand, "@ID", SqlDbType.Int, "ID", DataRowVersion.Current);

            db.UpdateDataSet(ds, ds.Tables[0].TableName, InsertCommand, UpdateCommand, DeleteCommand, UpdateBehavior.Standard);
        }
				
		public static void UpdateDataSet(DataSet ds, string tableName)
        {
            string insert = "Insert INTO t_NhanKhau_TomTatBanThan VALUES(@TuThangNamDenThangNam, @ChoO, @NgheNghiepNoiLamViec, @NhanKhauID)";
            string update = "UPDATE t_NhanKhau_TomTatBanThan SET TuThangNamDenThangNam = @TuThangNamDenThangNam, ChoO = @ChoO, NgheNghiepNoiLamViec = @NgheNghiepNoiLamViec, NhanKhauID = @NhanKhauID WHERE ID = @ID";
            string delete = "DELETE FROM t_NhanKhau_TomTatBanThan WHERE ID = @ID";

			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();

            System.Data.Common.DbCommand InsertCommand = db.GetSqlStringCommand(insert);
			db.AddInParameter(InsertCommand, "@ID", SqlDbType.Int, "ID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TuThangNamDenThangNam", SqlDbType.NVarChar, "TuThangNamDenThangNam", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ChoO", SqlDbType.NVarChar, "ChoO", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgheNghiepNoiLamViec", SqlDbType.NVarChar, "NgheNghiepNoiLamViec", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NhanKhauID", SqlDbType.BigInt, "NhanKhauID", DataRowVersion.Current);

            System.Data.Common.DbCommand UpdateCommand = db.GetSqlStringCommand(update);
			db.AddInParameter(UpdateCommand, "@ID", SqlDbType.Int, "ID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TuThangNamDenThangNam", SqlDbType.NVarChar, "TuThangNamDenThangNam", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ChoO", SqlDbType.NVarChar, "ChoO", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgheNghiepNoiLamViec", SqlDbType.NVarChar, "NgheNghiepNoiLamViec", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NhanKhauID", SqlDbType.BigInt, "NhanKhauID", DataRowVersion.Current);
			
            System.Data.Common.DbCommand DeleteCommand = db.GetSqlStringCommand(delete);
			db.AddInParameter(DeleteCommand, "@ID", SqlDbType.Int, "ID", DataRowVersion.Current);

            db.UpdateDataSet(ds, tableName, InsertCommand, UpdateCommand, DeleteCommand, UpdateBehavior.Standard);
        }

		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Select methods.
		
		public static NhanKhau_TomTatBanThan Load(int iD)
		{
			const string spName = "[dbo].[p_NhanKhau_TomTatBanThan_Load.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, iD);
            IDataReader reader = db.ExecuteReader(dbCommand);
			List<NhanKhau_TomTatBanThan> collection = ConvertToCollection(reader);	
			if (collection.Count > 0)
			{
				return collection[0];
			}
			return null;
		}		
		
		//---------------------------------------------------------------------------------------------
		public static List<NhanKhau_TomTatBanThan> SelectCollectionAll()
		{
			IDataReader reader = SelectReaderAll();
			return ConvertToCollection(reader);			
		}		
		
		//---------------------------------------------------------------------------------------------
		
		public static List<NhanKhau_TomTatBanThan> SelectCollectionDynamic(string whereCondition, string orderByExpression)
		{
			IDataReader reader = SelectReaderDynamic(whereCondition, orderByExpression);
			return ConvertToCollection(reader);		
		}
		
		//---------------------------------------------------------------------------------------------
		
		// Select by foreign key return collection		
		public static List<NhanKhau_TomTatBanThan> SelectCollectionBy_NhanKhauID(long nhanKhauID)
		{
            IDataReader reader = SelectReaderBy_NhanKhauID(nhanKhauID);
			return ConvertToCollection(reader);	
		}		
		//---------------------------------------------------------------------------------------------
		
		public static DataSet SelectBy_NhanKhauID(long nhanKhauID)
		{
			const string spName = "[dbo].[p_NhanKhau_TomTatBanThan_SelectBy_NhanKhauID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@NhanKhauID", SqlDbType.BigInt, nhanKhauID);
						
            return db.ExecuteDataSet(dbCommand);
		}
		//---------------------------------------------------------------------------------------------

		public static DataSet SelectAll()
        {
            const string spName = "[dbo].[p_NhanKhau_TomTatBanThan_SelectAll.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			
            return db.ExecuteDataSet(dbCommand);
        }
		
		//---------------------------------------------------------------------------------------------
		
		public static DataSet SelectDynamic(string whereCondition, string orderByExpression)
		{
            const string spName = "[dbo].[p_NhanKhau_TomTatBanThan_SelectDynamic.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            db.AddInParameter(dbCommand, "@OrderByExpression", SqlDbType.NVarChar, orderByExpression);
            
            return db.ExecuteDataSet(dbCommand);        				
		}
		
		//---------------------------------------------------------------------------------------------
				
		public static IDataReader SelectReaderAll()
        {
            const string spName = "[dbo].[p_NhanKhau_TomTatBanThan_SelectAll.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
            return db.ExecuteReader(dbCommand);
        }
		
		//---------------------------------------------------------------------------------------------
		
		public static IDataReader SelectReaderDynamic(string whereCondition, string orderByExpression)
		{
            const string spName = "[dbo].[p_NhanKhau_TomTatBanThan_SelectDynamic.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            db.AddInParameter(dbCommand, "@OrderByExpression", SqlDbType.NVarChar, orderByExpression);
            
            return db.ExecuteReader(dbCommand);        				
		}
		
		//---------------------------------------------------------------------------------------------
		
		// Select by foreign key return collection		
		public static IDataReader SelectReaderBy_NhanKhauID(long nhanKhauID)
		{
			const string spName = "p_NhanKhau_TomTatBanThan_SelectBy_NhanKhauID.generated";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@NhanKhauID", SqlDbType.BigInt, nhanKhauID);
			
            return db.ExecuteReader(dbCommand);
		}		
		//---------------------------------------------------------------------------------------------
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Insert methods.
		
		public static int InsertNhanKhau_TomTatBanThan(string tuThangNamDenThangNam, string choO, string ngheNghiepNoiLamViec, long nhanKhauID)
		{
			NhanKhau_TomTatBanThan entity = new NhanKhau_TomTatBanThan();	
			entity.TuThangNamDenThangNam = tuThangNamDenThangNam;
			entity.ChoO = choO;
			entity.NgheNghiepNoiLamViec = ngheNghiepNoiLamViec;
			entity.NhanKhauID = nhanKhauID;
			return entity.Insert();
		}
		
		public int Insert()
		{
			return this.Insert(null);
		}		
		
		//---------------------------------------------------------------------------------------------
		
		public int Insert(SqlTransaction transaction)
		{			
			const string spName = "[dbo].[p_NhanKhau_TomTatBanThan_Insert.generated]";		
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddOutParameter(dbCommand, "@ID", SqlDbType.Int, 4);
			db.AddInParameter(dbCommand, "@TuThangNamDenThangNam", SqlDbType.NVarChar, TuThangNamDenThangNam);
			db.AddInParameter(dbCommand, "@ChoO", SqlDbType.NVarChar, ChoO);
			db.AddInParameter(dbCommand, "@NgheNghiepNoiLamViec", SqlDbType.NVarChar, NgheNghiepNoiLamViec);
			db.AddInParameter(dbCommand, "@NhanKhauID", SqlDbType.BigInt, NhanKhauID);
			
			if (transaction != null)
			{
				db.ExecuteNonQuery(dbCommand, transaction);
				ID = (int) db.GetParameterValue(dbCommand, "@ID");
				return ID;
			}
            else
			{
				db.ExecuteNonQuery(dbCommand);
				ID = (int) db.GetParameterValue(dbCommand, "@ID");
				return ID;
			}			
		}
				
		//---------------------------------------------------------------------------------------------
		public static bool InsertCollection(List<NhanKhau_TomTatBanThan> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using(SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (NhanKhau_TomTatBanThan item in collection)
						{
							if (item.Insert(transaction) <= 0)
							{							
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at InsertCollection method: " + ex.Message);
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Insert / Update methods.
		
		public static int InsertUpdateNhanKhau_TomTatBanThan(int iD, string tuThangNamDenThangNam, string choO, string ngheNghiepNoiLamViec, long nhanKhauID)
		{
			NhanKhau_TomTatBanThan entity = new NhanKhau_TomTatBanThan();			
			entity.ID = iD;
			entity.TuThangNamDenThangNam = tuThangNamDenThangNam;
			entity.ChoO = choO;
			entity.NgheNghiepNoiLamViec = ngheNghiepNoiLamViec;
			entity.NhanKhauID = nhanKhauID;
			return entity.InsertUpdate();
		}
		
		//---------------------------------------------------------------------------------------------
		
		public int InsertUpdate()
		{
			return this.InsertUpdate(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int InsertUpdate(SqlTransaction transaction)
		{			
			const string spName = "p_NhanKhau_TomTatBanThan_InsertUpdate.generated";		
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, ID);
			db.AddInParameter(dbCommand, "@TuThangNamDenThangNam", SqlDbType.NVarChar, TuThangNamDenThangNam);
			db.AddInParameter(dbCommand, "@ChoO", SqlDbType.NVarChar, ChoO);
			db.AddInParameter(dbCommand, "@NgheNghiepNoiLamViec", SqlDbType.NVarChar, NgheNghiepNoiLamViec);
			db.AddInParameter(dbCommand, "@NhanKhauID", SqlDbType.BigInt, NhanKhauID);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);			
		}
		
		//---------------------------------------------------------------------------------------------
		public static bool InsertUpdateCollection(List<NhanKhau_TomTatBanThan> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (NhanKhau_TomTatBanThan item in collection)
						{
							if (item.InsertUpdate(transaction) <= 0)
							{
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at InsertUpdateCollection method: " + ex.Message);
						
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}	
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Update methods.
		
		public static int UpdateNhanKhau_TomTatBanThan(int iD, string tuThangNamDenThangNam, string choO, string ngheNghiepNoiLamViec, long nhanKhauID)
		{
			NhanKhau_TomTatBanThan entity = new NhanKhau_TomTatBanThan();			
			entity.ID = iD;
			entity.TuThangNamDenThangNam = tuThangNamDenThangNam;
			entity.ChoO = choO;
			entity.NgheNghiepNoiLamViec = ngheNghiepNoiLamViec;
			entity.NhanKhauID = nhanKhauID;
			return entity.Update();
		}
		
		//---------------------------------------------------------------------------------------------
		
		public int Update()
		{
			return this.Update(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int Update(SqlTransaction transaction)
		{
			const string spName = "[dbo].[p_NhanKhau_TomTatBanThan_Update.generated]";		
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, ID);
			db.AddInParameter(dbCommand, "@TuThangNamDenThangNam", SqlDbType.NVarChar, TuThangNamDenThangNam);
			db.AddInParameter(dbCommand, "@ChoO", SqlDbType.NVarChar, ChoO);
			db.AddInParameter(dbCommand, "@NgheNghiepNoiLamViec", SqlDbType.NVarChar, NgheNghiepNoiLamViec);
			db.AddInParameter(dbCommand, "@NhanKhauID", SqlDbType.BigInt, NhanKhauID);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);
		}
				
		//---------------------------------------------------------------------------------------------
		public static bool UpdateCollection(List<NhanKhau_TomTatBanThan> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (NhanKhau_TomTatBanThan item in collection)
						{
							if (item.Update(transaction) <= 0)
							{
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at UpdateCollection method: " + ex.Message);
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Delete methods.
		
		public static int DeleteNhanKhau_TomTatBanThan(int iD)
		{
			NhanKhau_TomTatBanThan entity = new NhanKhau_TomTatBanThan();
			entity.ID = iD;
			
			return entity.Delete();
		}
		
		public int Delete()
		{
			return this.Delete(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int Delete(SqlTransaction transaction)
		{
			const string spName = "[dbo].[p_NhanKhau_TomTatBanThan_Delete.generated]";		
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, ID);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
		
		public static int DeleteBy_NhanKhauID(long nhanKhauID)
		{
			const string spName = "[dbo].[p_NhanKhau_TomTatBanThan_DeleteBy_NhanKhauID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@NhanKhauID", SqlDbType.BigInt, nhanKhauID);
						
            return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
			
		
		public static int DeleteDynamic(string whereCondition)
		{
			const string spName = "[dbo].[p_NhanKhau_TomTatBanThan_DeleteDynamic.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            
            return db.ExecuteNonQuery(dbCommand);   
		}
		//---------------------------------------------------------------------------------------------
		
		public static bool DeleteCollection(List<NhanKhau_TomTatBanThan> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (NhanKhau_TomTatBanThan item in collection)
						{
							if (item.Delete(transaction) <= 0)
							{
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at DeleteCollection method: " + ex.Message);
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}
		#endregion
		
        //---------------------------------------------------------------------------------------------
		
        #region ICloneable Members

        public object Clone()
        {
            return base.MemberwiseClone();
        }

        public NhanKhau_TomTatBanThan CloneObject()
        {
            return this.Clone() as NhanKhau_TomTatBanThan;
        }
        
        #endregion
	}	
}